<template>
  <div class="favor">
    <NavBar left-arrow left-text="返回" class="NavBar">
      <template #title>
        <van-tabs v-model:active="active" type="card">
          <van-tab :title="titles[0]"> </van-tab>
          <van-tab :title="titles[1]"> </van-tab>
        </van-tabs>
      </template>
    </NavBar>

    <div class="Myfavor" v-if="active === 0">
      <van-tabs v-model:active="favorActive" class="Myfavor-van-tabs">
        <van-tab title="房屋" class="title">
          <div class="SearchListItem">
            <SearchListItem :items="items"></SearchListItem>
          </div>
        </van-tab>
        <van-tab title="房东" class="title">
          <div class="content">
            <div class="no-data">
              <img
                class="no-data-img"
                src="@/assets/img/favor/empty_favorite.44731802.png"
                alt=""
              />
            </div>
            <div class="name">暂无收藏</div>
            <div class="desp">
              点击
              <img class="img" src="@/assets/img/favor/favor.png" alt="" />
              即可收藏对应的房东
            </div>
            <button class="btn" @click="handleBtnClick">随便去逛逛</button>
          </div>
        </van-tab>
      </van-tabs>
    </div>

    <div class="history" v-if="active === 1">
      <SearchListItem :items="historyItems"></SearchListItem>
    </div>
  </div>
</template>

<script setup>
  import { ref, computed } from 'vue'
  import NavBar from '@/components/nav-bar/nav-bar.vue'
  import SearchListItem from '@/components/search-list-item/search-list-item.vue'
  import useFavorStore from '@/stores/modules/favor'
  import useFavorHistoryStore from '@/stores/modules/history'
  import { storeToRefs } from 'pinia'
  import { useRouter } from 'vue-router'
  const active = ref(0)
  const favorActive = ref(0)
  const titles = ['我的收藏', '浏览历史']

  // favor 发送网络请求
  const favorStore = useFavorStore()
  favorStore.fetchFavorData()
  const { favor } = storeToRefs(favorStore)

  const items = computed(() => {
    return favor.value?.items
  })

  // FavorHistory 发送网络请求
  const historyStore = useFavorHistoryStore()
  historyStore.fetchFavorHistoryData()
  const { history } = storeToRefs(historyStore)

  const historyItems = computed(() => {
    return history.value?.items
  })

  const router = useRouter()
  const handleBtnClick = () => {
    router.push('/')
  }
</script>

<style lang="less" scoped>
  /* 重写Vant 样式 */
  :global(.favor .van-nav-bar .van-nav-bar__content .van-nav-bar__title) {
    width: 50% !important;
    font-weight: 400 !important;
  }
  :global(.NavBar .van-tab--active) {
    font-weight: 300 !important;
    transition: all 0.3s ease !important;
    // width: 100px !important;
  }
  :global(.Myfavor-van-tabs .van-tab) {
    font-size: 16px !important;
    font-weight: 400 !important;
   
  }

  .favor {
    background-color: #f7f8fb;

    .Myfavor {
      background-color: #f7f8fb;
      height: 93vh;
      .SearchListItem {
        margin-top: 20px;
        padding: 0 0 50px;
      }
      .content {
        display: flex;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        .no-data {
          .no-data-img {
            width: 100%;
          }
        }
        .desp {
          margin-top: 20px;
          font-size: 14px;
          color: #666;
          .img {
            position: relative;
            top: 4px;
            width: 12px;
          }
        }
        .btn {
          padding: 0 38px;
          height: 40px;
          line-height: 40px !important;
          font-size: 16px;
          color: #fff;
          background: var(--primary-color);
          border-radius: 20px;
          border: none;
          outline: none;
          margin-top: 30px;
        }
      }
    }
    .history {
      padding: 0 0 50px;
    }
  }
</style>
